
// This class contains data for an individual item in a
// shopping cart.

package shoppingCart;

import java.math.BigDecimal;
import java.net.URL;

public class ShoppingCartItem implements Cloneable
{
	public int itemID;
	public String itemName;
	public String itemDesc;
	public BigDecimal itemCost;
	public int quantity;
	public int amount;

	public ShoppingCartItem()
	{
	}

	public ShoppingCartItem(int itemID, String itemName, String itemDesc, 
			BigDecimal itemCost, int quantity)
	{
		this.itemID = itemID;
		this.itemName = itemName;
		this.itemDesc = itemDesc;
		this.itemCost = itemCost;
		this.quantity = quantity;
	}

// The add method is a quick method for combining two similar
// items. It doesn't perform any checks to insure that they are
// similar, however. You use this method when adding items to a
// cart, rather than storing two instances of the same item, you
// add the quantities together.

	public void add(ShoppingCartItem otherItem)
	{
		this.quantity = this.quantity + otherItem.quantity;
	}

// The subtract method is similar to the add method, but it
// removes a certain quantity of items.

	public void subtract(ShoppingCartItem otherItem)
	{
		this.quantity = this.quantity - otherItem.quantity;
	}

// You can store items in a hash table if you implement hashCode. It's
// always a good idea to do this.

	public int hashCode()
	{
		return itemName.hashCode() + itemCost.intValue();
	}

// The equals method does something a little dirty here, it only
// compares the item names and item costs. Technically, this is
// not the way that equals was intended to work.

	public boolean equals(Object other)
	{
		if (this == other) return true;

		if (!(other instanceof ShoppingCartItem))
			return false;

		ShoppingCartItem otherItem =
			(ShoppingCartItem) other;

		return (itemName.equals(otherItem.itemName)) &&
			(itemCost == otherItem.itemCost);
	}

// Create a copy of this object

	public ShoppingCartItem copy()
	{
		return new ShoppingCartItem(itemID, itemName, itemDesc, itemCost,
			quantity);
	}

// Create a printable version of this object

	public String toString()
	{
		String currentItem = "ID: " + itemID + " " + itemName + "-" + itemDesc 
				+ "\t"+ "qty: " + quantity +" \t cost: " + itemCost + " kr";
		return currentItem;
	}
}

